<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 相加等于数字n的完全平方数的最少数量 -->
    <script>
      var numSquares = function (num) {
        let res = [0]
        for (let i = 1; i < num + 1; i++) {
          res[i] = i
          for (let j = 1; j * j <= i; j++) {
            res[i] = Math.min(res[i], res[i - j * j] + 1)
          }
        }
        return res[num]
      }
      console.log(numSquares(12))
    </script>
  </body>
</html>
